#define CATCH_CONFIG_MAIN  // 如果需要定义该宏，则必须定义在包含catch.hpp之前；否则出现链接错误
#include "../test/catch.hpp"
#include "binary_find.h"
void Print(std::vector<int>& v) {
  for (auto& t : v) {
    std::cout << t << " ";
  }
  std::cout << std::endl;
}
TEST_CASE("binary_sort", "") {
  std::vector<int> v{-9, -3, 0, 10, 10, 10, 10, 10, 76, 89};
  // Print(v);
  // 每个SECTION都会重新执行TEST_CASE,如果取消掉Print(v)的注释，可以看到它被调用了三次
  SECTION("find_any") {
    REQUIRE(BinaryFindAny1(v, 10) <= 7);
    REQUIRE(BinaryFindAny1(v, 10) >= 3);
    REQUIRE(BinaryFindAny2(v, 10) <= 7);
    REQUIRE(BinaryFindAny2(v, 10) >= 3);
  }
  SECTION("find_left") {
    REQUIRE(BinaryFindLeft1(v, 10) == 3);
    REQUIRE(BinaryFindLeft2(v, 10) == 3);
  }
  SECTION("find_right") {
    REQUIRE(BinaryFindRight1(v, 10) == 7);
    REQUIRE(BinaryFindRight2(v, 10) == 7);
  }
}
